//
//  ByUIPersonSettingVC.m
//  itboye_shop_ios
//
//  Created by justiOS on 17/2/10.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIPersonSettingVC.h"

// vc
#import "ByUIMineDataVC.h"            // 个人资料
#import "ByUIAccountsSecurityVC.h"    // 账户与安全
#import "ByUIAboutVC.h"               // 关于
#import "ByTabBarController.h"
@interface ByUIPersonSettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) UIButton *logoutButton;
@property (nonatomic, strong) NSArray *nameAry;
@property (nonatomic, strong) NSArray *iconAry;
@end

@implementation ByUIPersonSettingVC
#pragma mark getter
- (UITableView *)table {
    if (!_table) {
        _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 -49) style:UITableViewStylePlain];
        _table.delegate = self;
        _table.dataSource = self;
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
        _table.backgroundColor = TABLE_COLOR;
    }
    return _table;
}


- (UIButton *)logoutButton {
    if (!_logoutButton) {
        _logoutButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _logoutButton.frame = CGRectMake(0, SCREEN_HEIGHT - 64 - 49, SCREEN_WIDTH, 49);
        _logoutButton.backgroundColor = BY_THEME_COLOR;
        [_logoutButton setTitle:@"退出当前账户" forState:UIControlStateNormal];
        [_logoutButton addTarget:self action:@selector(logoutAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _logoutButton;
}

- (NSArray *)nameAry {
    if (!_nameAry) {
        _nameAry = @[@"个人资料",@"账户与安全",@"新消息通知",@"关于博也"];
    }
    return _nameAry;
}
- (NSArray *)iconAry {
    if (!_iconAry) {
        _iconAry = @[@"mine_people",@"mine_people",@"mine_people",@"mine_people"];
    }
    return _iconAry;
}


#pragma mark ui
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self addLeftBackBarButtonItem];
    [self createViews];
}

- (void)createViews {
    [self.view addSubview:self.logoutButton];
    [self.view addSubview:self.table];

}


#pragma mark tableView Delegate and DateSource

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"normalCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    UIImage *image = [UIImage imageNamed:self.iconAry[indexPath.row]];
//    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(11, 11, 22, 22)];
//    imageView.image = image;
//    [cell addSubview:imageView];
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(44, 12, SCREEN_WIDTH - 80, 20)];
//    label.text = self.nameAry[indexPath.row];
//    label.textColor = [UIColor darkGrayColor];
//    label.font = FONT(16);
//    [cell addSubview:label];
    
    cell.imageView.frame = CGRectMake(11, 11, 22, 22);
    cell.imageView.image = image;
    cell.imageView.layer.cornerRadius = 1;
    cell.textLabel.text = self.nameAry[indexPath.row];
    cell.textLabel.font = FONT(16);
    cell.textLabel.textColor = [UIColor darkGrayColor];
    
    if (indexPath.row == self.nameAry.count - 1) {
        
    }else{
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(44, 43.5, SCREEN_WIDTH - 44, 0.5)];
        line.backgroundColor = BY_LINE_COLOR;
        [cell addSubview:line];
    }
    
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.nameAry.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        ByUIMineDataVC *vc = [[ByUIMineDataVC alloc] init];
        [self by_normalPush:vc hasNavi:YES];
    }else if (indexPath.row == 1){
        ByUIAccountsSecurityVC *vc = [[ByUIAccountsSecurityVC alloc] init];
        [self by_normalPush:vc hasNavi:YES];
    }else if (indexPath.row == 2){
    
    }else if (indexPath.row == 3){
        ByUIAboutVC *vc = [[ByUIAboutVC alloc] init];
        [self by_normalPush:vc hasNavi:YES];
    }
}


#pragma mark 点击事件
- (void)logoutAction:(UIButton *)button {
    [ByCacheUser setUserInfo:nil];
    [self dismissViewControllerAnimated:YES completion:^{
        ByTabBarController *tab = (ByTabBarController *)((AppDelegate *)BY_APPDELEGATE).window.rootViewController;
        tab.selectedIndex = 0;
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
